package com.linkage.seapeak.view;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetDialog;
import android.view.View;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.linkage.jz.bankruptcy.R;

public class CreditorOrderDialog extends BottomSheetDialog {

    Context context;
    private TextView btnSure;

    private OnSureListener sureListener;
    private RadioGroup orderType;
    private RadioGroup order;

    public CreditorOrderDialog(@NonNull Context context) {
        super(context);
    }

    public CreditorOrderDialog(@NonNull Context context, int theme) {
        super(context, theme);
    }

    protected CreditorOrderDialog(@NonNull Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    public void setSureListener(OnSureListener sureListener) {
        this.sureListener = sureListener;
    }

    public void init(Context context, String orderTypeString, String orderString) {
        this.context = context;
        setContentView(R.layout.view_dialog_creditor_order);
        btnSure = (TextView) findViewById(R.id.btn_sure);
        orderType = (RadioGroup) findViewById(R.id.order_type);
        order = (RadioGroup) findViewById(R.id.order);

        if (orderTypeString.equals("confirmAmount"))
            orderType.check(R.id.select_1);
        else if (orderTypeString.equals("amountDeclared"))
            orderType.check(R.id.select_2);
        else if (orderTypeString.equals("confirmTime"))
            orderType.check(R.id.select_3);
        else if (orderTypeString.equals("declareTime"))
            orderType.check(R.id.select_4);

        if (orderString.equals("desc"))
            order.check(R.id.select_big2small);
        else if (orderString.equals("asc"))
            order.check(R.id.select_small2big);

        btnSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int orderTypeInt = orderType.getCheckedRadioButtonId();
                int orderInt = order.getCheckedRadioButtonId();
                if (orderTypeInt == R.id.select_1)
                    orderTypeInt = 1;
                else if (orderTypeInt == R.id.select_2)
                    orderTypeInt = 2;
                else if (orderTypeInt == R.id.select_3)
                    orderTypeInt = 3;
                else if (orderTypeInt == R.id.select_4)
                    orderTypeInt = 4;
                else
                    orderTypeInt = 0;

                if (orderInt == R.id.select_big2small)
                    orderInt = 1;
                else if (orderInt == R.id.select_small2big)
                    orderInt = 2;
                else
                    orderInt = 0;

                if (sureListener != null)
                    sureListener.onSure(orderTypeInt, orderInt);
            }
        });
    }

    public void preCheck() {

    }

    public interface OnSureListener {
        void onSure(int orderType, int orderOrien);
    }
}
